//
//  Selection.m
//  LiWuShuo
//
//  Created by 袁小航 on 14/11/13.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "Selection.h"
#import "Define.h"

@implementation Selection

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
//        创建rootCollectionView
        [self createRootCollectionView];
        
//        创建精选页顶端的ScrollView
        [self createRootScrollView];
        
    }
    return self;
}


#pragma mark -
#pragma mark 创建rootCollectionView
- (void)createRootCollectionView
{
    self.rootLayout = [[UICollectionViewFlowLayout alloc]init];
    self.rootLayout.itemSize = CGSizeMake(PRO_IMAGE_WIDTH - 14, ((PRO_IMAGE_HEIGHT - 40) / 3));
    
    self.rootCollectionView = [[UICollectionView alloc]initWithFrame:self.bounds collectionViewLayout:self.rootLayout];
//    点击之后返回顶部
    self.rootCollectionView.scrollsToTop = YES;
    
    self.rootCollectionView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_rootCollectionView];
}

#pragma mark -
#pragma mark 创建精选页顶端的scrollView
- (void)createRootScrollView
{
    self.rootTopView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, PRO_IMAGE_WIDTH, 130)];
    [_rootCollectionView addSubview:_rootTopView];
    
    self.rootScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, PRO_IMAGE_WIDTH, 130)];
//    整页滚动
    _rootScrollView.pagingEnabled = YES;
    _rootScrollView.scrollsToTop = NO;
    _rootScrollView.showsHorizontalScrollIndicator = NO;

    [_rootTopView addSubview:_rootScrollView];
    
    self.rootPage = [[UIPageControl alloc]initWithFrame:CGRectMake(0, SEL_SCROLL_HEIGHT - SEL_PAGE_HEIGHT + 10, PRO_IMAGE_WIDTH, SEL_PAGE_HEIGHT)];
    _rootPage.currentPageIndicatorTintColor = [UIColor redColor];
    _rootPage.currentPage = 0;
    [_rootTopView addSubview:_rootPage];
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
